Quiz: Operators and Expression

To View Tricks: Login Required

Number of Questions: 12

Question: 1 -

4 is 100 in binary and 11 is 1011. What is the output of the following bitwise operators?

a = 4
b = 11
print(a | b)
print(a >> 2)

Options:
  1. 15
    10

  2. 1
    15

  3. 14
    1

  4. 15
    1

  5. Answer:

    15
    1

    Solution:

    Bitwise right shift operator(>>): The a’s value is moved right by the 2 bits.


Question: 2 -

Which of the following operators has the highest precedence?

Options:
  1. +

  2. &

  3. *

  4. not

  5. Answer:

    *

    Solution not available.

Question: 3 -

What is the output of the following code

print(bool(0), bool(3.14159), bool(-3), bool(1.0+1j))

Options:
  1. False True True True

    • True True False True
  2. True True False True

  3. False True False True

  4. Answer:

    False True True True

    Solution:

    • If we pass A zero value to bool() constructor, it will treat it as a boolean False.
    • Any non-zero value will be treated as a boolean True.


Question: 4 -

What is the output of the expression  print(-18 // 4)

Options:
  1. 4

  2. -4

  3. -5

  4. 5

  5. Answer:

    -5

    Solution:

    In the case of floor division operator (//), when the result is negative, the result is rounded down to the next smallest (big negative) integer.


Question: 5 -

What is the output of the following code

x = 100
y = 50
print(x and y)

Options:
  1. False

  2. 50

  3. True

  4. 100

  5. Answer:

    50

    Solution:

    In Python, When we join two non-Boolean values using a and operator, the value of the expression is the second operands, not True or False.